﻿using System.Text;

namespace IBNet
{
   /// <summary>
   /// Preallocated byte arrays for improved outgoing network performance.
   /// </summary>
   public static class PreallocatedByteArrays
   {
      public readonly static byte[] Zero = ToByteArray("0");
      public readonly static byte[] One = ToByteArray("1");
      public readonly static byte[] False = Zero;
      public readonly static byte[] True = One;
      public readonly static byte[] Two = ToByteArray("2");
      public readonly static byte[] Three = ToByteArray("3");
      public readonly static byte[] Four = ToByteArray("4");
      public readonly static byte[] Five = ToByteArray("5");
      public readonly static byte[] Six = ToByteArray("6");
      public readonly static byte[] Seven = ToByteArray("7");
      public readonly static byte[] Eight = ToByteArray("8");
      public readonly static byte[] TwentySix = ToByteArray("26");
      public readonly static byte[] TwentySeven = ToByteArray("27");

      public readonly static byte[] OneYear = ToByteArray("1 Y");

      public readonly static byte[] RequestMarketData = ToByteArray(((int)OutgoingMessage.RequestMarketData).ToString());
      public readonly static byte[] CancelMarketData = ToByteArray(((int)OutgoingMessage.CancelMarketData).ToString());
      public readonly static byte[] PlaceOrder = ToByteArray(((int)OutgoingMessage.PlaceOrder).ToString());
      public readonly static byte[] CancelOrder = ToByteArray(((int)OutgoingMessage.CancelOrder).ToString());
      public readonly static byte[] RequestOpenOrders = ToByteArray(((int)OutgoingMessage.RequestOpenOrders).ToString());
      public readonly static byte[] RequestAccountData = ToByteArray(((int)OutgoingMessage.RequestAccountData).ToString());
      public readonly static byte[] RequestExecutions = ToByteArray(((int)OutgoingMessage.RequestExecutions).ToString());
      public readonly static byte[] RequestIds = ToByteArray(((int)OutgoingMessage.RequestIds).ToString());
      public readonly static byte[] RequestContractData = ToByteArray(((int)OutgoingMessage.RequestContractData).ToString());
      public readonly static byte[] RequestMarketDepth = ToByteArray(((int)OutgoingMessage.RequestMarketDepth).ToString());
      public readonly static byte[] CancelMarketDepth = ToByteArray(((int)OutgoingMessage.CancelMarketDepth).ToString());
      public readonly static byte[] RequestNewsBulletins = ToByteArray(((int)OutgoingMessage.RequestNewsBulletins).ToString());
      public readonly static byte[] CancelNewsBulletins = ToByteArray(((int)OutgoingMessage.CancelNewsBulletins).ToString());
      public readonly static byte[] SetServerLogLevel = ToByteArray(((int)OutgoingMessage.SetServerLogLevel).ToString());
      public readonly static byte[] RequestAutoOpenOrders = ToByteArray(((int)OutgoingMessage.RequestAutoOpenOrders).ToString());
      public readonly static byte[] RequestAllOpenOrders = ToByteArray(((int)OutgoingMessage.RequestAllOpenOrders).ToString());
      public readonly static byte[] RequestManagedAccounts = ToByteArray(((int)OutgoingMessage.RequestManagedAccounts).ToString());
      public readonly static byte[] RequestFA = ToByteArray(((int)OutgoingMessage.RequestFA).ToString());
      public readonly static byte[] ReplaceFA = ToByteArray(((int)OutgoingMessage.ReplaceFA).ToString());
      public readonly static byte[] RequestHistoricalData = ToByteArray(((int)OutgoingMessage.RequestHistoricalData).ToString());
      public readonly static byte[] ExerciseOptions = ToByteArray(((int)OutgoingMessage.ExerciseOptions).ToString());
      public readonly static byte[] RequestScannerSubscription = ToByteArray(((int)OutgoingMessage.RequestScannerSubscription).ToString());
      public readonly static byte[] CancelScannerSubscription = ToByteArray(((int)OutgoingMessage.CancelScannerSubscription).ToString());
      public readonly static byte[] RequestScannerParameters = ToByteArray(((int)OutgoingMessage.RequestScannerParameters).ToString());
      public readonly static byte[] CancelHistoricalData = ToByteArray(((int)OutgoingMessage.CancelHistoricalData).ToString());
      public readonly static byte[] RequestCurrentTime = ToByteArray(((int)OutgoingMessage.RequestCurrentTime).ToString());
      public readonly static byte[] RequestRealTimeBars = ToByteArray(((int)OutgoingMessage.RequestRealTimeBars).ToString());
      public readonly static byte[] CancelRealTimeBars = ToByteArray(((int)OutgoingMessage.CancelRealTimeBars).ToString());
      public readonly static byte[] RequestFundamentalData = ToByteArray(((int)OutgoingMessage.RequestFundamentalData).ToString());
      public readonly static byte[] CancelFundamentalData = ToByteArray(((int)OutgoingMessage.CancelFundamentalData).ToString());

      private static byte[] ToByteArray(string value)
      {
         byte[] stringAsByteArray = UTF8Encoding.UTF8.GetBytes(value);
         return stringAsByteArray;
      }
   }
}
